package com.sias.oj.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户角色枚举
 *
 * @author <a href="https://github.com/sogra">程序员sogra</a>
 */
public enum QuestionSubmitStatusEnum {

  //
  WAITING("等待", 0),

  RUNNING("判题中", 1),

  SUCCEED("成功", 2),

  FAILURE("失败", 2);

  private final String text;

  private final Integer value;

  QuestionSubmitStatusEnum(String text, Integer value) {
    this.text = text;
    this.value = value;
  }

  /**
   * 获取值列表
   *
   * @return
   */
  public static List<Integer> getValues() {
    return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
  }

  /**
   * 根据 value 获取枚举
   *
   * @param value
   * @return
   */
  public static QuestionSubmitStatusEnum getEnumByValue(Integer value) {
    if (ObjectUtils.isEmpty(value)) {
      return null;
    }
    for (QuestionSubmitStatusEnum anEnum : QuestionSubmitStatusEnum.values()) {
      if (anEnum.value.equals(value)) {
        return anEnum;
      }
    }
    return null;
  }

  public Integer getValue() {
    return value;
  }

  public String getText() {
    return text;
  }
}
